<template>
  <el-dialog
    title="发送topic消息"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <!--<el-form-item label="topic" prop="topic">-->
      <!--<el-input v-model="dataForm.topic" placeholder="topic"></el-input>-->
    <!--</el-form-item>-->
    <!--<el-form-item label="请求数次" prop="requestNum">-->
      <!--<el-input v-model="dataForm.requestNum" placeholder="请求数次"></el-input>-->
    <!--</el-form-item>-->
    <!--<el-form-item label="请求权限" prop="requestAuth">-->
      <!--<el-input v-model="dataForm.requestAuth" placeholder="请求权限"></el-input>-->
    <!--</el-form-item>-->
    <!--<el-form-item label="" prop="createDate">-->
      <!--<el-input v-model="dataForm.createDate" placeholder=""></el-input>-->
    <!--</el-form-item>-->
    <el-form-item label="请输入要发送的内送" prop="modifyDate">
      <el-input type="textarea" maxlength="500"  v-model="dataForm.message" :autosize="{ minRows: 4, maxRows: 8}"></el-input>
    </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          topic: 0,
          message: ''
        },
        dataRule: {
          message: [
            { required: true, message: 'message不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (topic) {
        this.dataForm.topic = topic || 0

        this.visible = true
        // this.$nextTick(() => {
        //   this.$refs['dataForm'].resetFields()
        //   if (this.dataForm.id) {
        //     this.$http({
        //       url: this.$http.adornUrl(`/generator/ttopic/info/${this.dataForm.id}`),
        //       method: 'get',
        //       params: this.$http.adornParams()
        //     }).then(({data}) => {
        //       if (data && data.code === 0) {
        //         this.dataForm.topic = data.ttopic.topic
        //         this.dataForm.requestNum = data.ttopic.requestNum
        //         this.dataForm.requestAuth = data.ttopic.requestAuth
        //         this.dataForm.createDate = data.ttopic.createDate
        //         this.dataForm.modifyDate = data.ttopic.modifyDate
        //       }
        //     })
        //   }
        // })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/ttopic/sendAliTopicMessage`),
              method: 'post',
              params: {
                'topic': this.dataForm.topic,
                'message': this.dataForm.message
              }
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
